$(function () {
    listCount('PACKAGE');
    //加载课程数据
    listCourse(1);
    $("body").on('click', '#btn1,#btn2', function () { //搜索课程
        listCourse(1);
    }).on('click','#copy-course',function () {//复制课程
        var courseId = $(this).data('id');
        copyCourse(courseId,function () {
            window.location.href = baseloaction +'/admin/course/package/toPackageCourseList';
        })
    }).on("click",".share-to-user",function () {
        var courseId = $(this).data("id");
        shareAddressFn(courseId,"VIDEO");
    })
    //加载课程数据
    function listCourse(page) {
        var params = $("#search-form").serializeJSON();
        params = JSON.stringify(params);
        var obj = {
            url: baseloaction + '/admin/course/package/ajaxPackageCourseList',//请求URL
            contextId: 'course-list-context',//响应内容页面设置内容ID
            params: params,//请求参数
            pageNo: page,//页码
            pageCall: listCourse, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            selectAllId: 'all-course', //全选框ID
            callback: function () {//数据加载完成回调
                $("#count").html('（共'+total+'个套餐课程）');
                lazyCourseImage();
            }
        };
        ajaxGetListData(obj);
    }
});

function shareAddressFn(id,type) {
    parent.layer.open({
        type: 2,
        area: ['320px', '420px'],
        skin: 'layui-layer-demo',
        title: '分享地址',
        btn:false,
        content: [`${baseloaction}/admin/course/cou/shareCourseToUser?courseId=${id}&type=${type}`,'no']
    })
}